new Vue({
    el: '#app',
    mixins: [Save],//组件配置文件，路径/utils/components.js
    data() {
        return {
            dataForm: {},
            childDataForm: [{}],//子表
            article_brand: [],//品牌
            article_type: [],//商品类型
            article_category: [],//商品类别
            article_item: [],//商品款型
            article_series: [],//商品系列
            article_pictures: [{}],//商品图片
        }
    },
    mounted() {
        /**
         * 组件配置文件中自动执行方法
         * 1.this.init(); //初始化文件
         * 2.this.getData(); //仅修改时执行，根据BOM配置属性查询
         */
        this.getList();
        let ls_URL = window.location.href;
        this.type = getQueryObject(ls_URL, "type") || '0';
    },
    methods: {
        getList() {
            // 获取商品品牌列表，仅显示本公司下的品牌
            // 如果 enterprise != '1'，则添加公司筛选条件，只显示当前公司的品牌
            const enterprise = getCookie('enterprise');
            const brandCondition = enterprise != '1'
                ? `Row_Status='0' AND Enterprise_Info_SerialNumber='${enterprise}'`
                : `Row_Status='0'`;
            httpRequest({
                url: '/generalBusiness/generalQueryByTableName',
                data: {
                    Data: 'article_brand',
                    Condition: brandCondition
                },
                type: 'GET'
            }).then(data => {
                this.article_brand = data || [];
            }).catch(xhr => {
                this.$message.error("获取商品品牌列表失败，请联系开发者!")
            })

            httpRequest({
                url: '/generalBusiness/generalQueryByTableName',
                data: {
                    Data: 'article_type',
                    Condition: `Row_Status='0'`
                },
                type: 'GET'
            }).then(data => {
                this.article_type = data;
            }).catch(xhr => {
                this.$message.error("系统错误，请联系开发者!")
            })

            httpRequest({
                url: '/generalBusiness/generalQueryByTableName',
                data: {
                    Data: 'article_category',
                    Condition: `Row_Status='0'`
                },
                type: 'GET'
            }).then(data => {
                this.article_category = data;
            }).catch(xhr => {
                this.$message.error("系统错误，请联系开发者!")
            })

            httpRequest({
                url: '/generalBusiness/generalQueryByTableName',
                data: {
                    Data: 'article_item',
                    Condition: `Row_Status='0'`
                },
                type: 'GET'
            }).then(data => {
                this.article_item = data;
            }).catch(xhr => {
                this.$message.error("系统错误，请联系开发者!")
            })

            httpRequest({
                url: '/generalBusiness/generalQueryByTableName',
                data: {
                    Data: 'article_series',
                    Condition: `Row_Status='0'`
                },
                type: 'GET'
            }).then(data => {
                this.article_series = data;
            }).catch(xhr => {
                this.$message.error("系统错误，请联系开发者!")
            })

        },
        // 获取商品列表
        getArticleList() {
            generalApi.generalQueryByTableName({
                Data: 'article_brand',
                Condition: `Row_Status='0' AND Enterprise_Info_SerialNumber='${getCookie('enterprise')}'`
            }).then(data => {
                this.articleList = data || [];
            }).catch(xhr => {
                this.$message.error("获取商品列表失败，请联系开发者!")
            })
        },
        handleDetail(row) {
            try {
                const { primaryKey } = $('#table').data('options');
                window.location.href = "./add.html?action=Modify&type=1&nodeKey=" + row[primaryKey];
            } catch (error) {
                console.error(error);
                this.$message({
                    message: '系统错误，请联系开发者!',
                    type: 'error'
                })
            }
        }
    }
})